var api = require('../../util/api.js');

Page({
    data: {
        name: '',
        tel: ''
    },
    onLoad: function () {

    },
    inputName(e) {
        this.setData({
            name: e.detail.value
        })
    },
    inputCode(e) {
        this.setData({
            tel: e.detail.value
        })
    },
    bangding(e) {
        if (this.data.name == '') {
            wx.showToast({
                title: "请填写姓名",
                icon: 'none'
            })
            return
        }
        if (this.data.tel == '') {
            wx.showToast({
                title: '请填写电话',
                icon: 'none'
            })
            return
        }
        var reg = /^1[3456789]\d{9}$/;
        if (!reg.test(this.data.tel)) {
            wx.showToast({
                title: '手机号不正确',
                icon: 'none'
            })
            return
        }
        api.post(api.url.bound, {
            'params[openid]': wx.getStorageSync('openid'),
            'params[appid]': wx.getStorageSync('appid'),
            phonenumber: this.data.tel,
            userName: this.data.name,
            _noAuth: true
        }).then(res => {
            api.syncToken().then(res=>{
                api.syncCurrUser().then(res1=>{
                    wx.switchTab({
                        url: '/pages/gsjj/gsjj'
                    })
                });
            });
        });
    }
});